package com.yuke.cloud.service.omc.utils;

import com.yuke.cloud.service.omc.redis.RedisCacheTemplate;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yuke-mall </br> </p>
 * <p>com.yuke.cloud.service.omc.utils Description TODO </br> </p>
 * @Author wg
 * @Date   2020/4/23 14:39
 */
public class SequenceUtils {

    private RedisCacheTemplate redisCacheTemplate;

    static final String  SERIAL_NUM= "redis:serialNumber:";

    static final int DEFAULT_LENGTH = 4;

    public static String getSequence(long seq) {
        String str = String.valueOf(seq);
        int len = str.length();
        if (len >= DEFAULT_LENGTH) {// 取决于业务规模,应该不会到达3
            return str;
        }
        int rest = DEFAULT_LENGTH - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rest; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }

    public static String getSequence(long seq, int length) {
        String str = String.valueOf(seq);
        int len = str.length();
        length = Math.max(length, DEFAULT_LENGTH);
        if (len >= length) {
            return str;
        }
        int rest = length - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rest; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }


}
